<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>页面控制台 - WingsJ</title>

  <style>
    html {
      font-size: 20px;
      font-family: 'Microsoft Jhenghei';
    }

    body {
      padding: 4rem;
    }
  </style>
  <script type="module">
    import Stats from './lib/stats.module.js';
    import { GUI } from './lib/dat.gui.module.js';

    window.Control = {}

    const AnimationArray = [ // 需要周期调用的函数添加到这个数组中
      () => {
        window.requestAnimationFrame(timestamp => {
          for (let el of AnimationArray) {
            el(timestamp)
          }
        })
      }
    ]
    window.Control.AnimationArray = AnimationArray

    const stats = new Stats()
    AnimationArray.push(() => {
      stats.update()
    })
    const gui = new GUI();
    window.Control.GUI = gui

    document.addEventListener('DOMContentLoaded', () => {
      document.body.appendChild(stats.dom)
      window.requestAnimationFrame(AnimationArray[0])
    })
  </script>

  <style>
    .div {
      width: 100px;
      height: 100px;
      margin-bottom: 2rem;
      background-color: skyblue;

    }

    #div-1 {
      opacity: 1;
      visibility: visible;
      transition: opacity 0.5s, visibility 0.5s;
    }

    #div-1.hidden {
      opacity: 0;
      visibility: hidden;
    }

    #div-2.hidden {
      animation: fade 0.5s forwards;
    }

    @keyframes fade {
      from {
        opacity: 1;
      }

      to {
        opacity: 0;
        display: none;
      }
    }
  </style>
</head>

<body>
  <div>#1-transition，visibility</div>
  <div id="div-1" class="div"></div>

  <div>#2-animation，display</div>
  <div id="div-2" class="div"></div>

  <script type="module">
    let param = {
      toggle_1: () => {
        document.getElementById('div-1').classList.toggle('hidden')
      },
      toggle_2: () => {
        document.getElementById('div-2').classList.toggle('hidden')
      }
    }
    for (let key in param) {
      Control.GUI.add(param, key)
    }

  </script>
</body>

</html>